package org.linuxsogood.boot.ch2;

import org.linuxsogood.boot.ch2.vo.Apple;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author honway.liu
 * @date 2017/7/4 下午10:47
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class FilterApple {

    public static void main(String[] args) {
        List<Apple> apples = new ArrayList<Apple>();
        apples.add(new Apple(5, "green"));
        apples.add(new Apple(3, "red"));
        apples.add(new Apple(7, "blue"));
        apples.add(new Apple(12, "black"));
        apples.add(new Apple(98, "pink"));
        apples.add(new Apple(98, "gray"));
        apples.add(new Apple(98, "cmyk"));

        apples.sort(Comparator.comparing(Apple::getWeight).thenComparing(Apple::getColor));
        System.out.println(apples);
    }

    private static List<Apple> tradionalFilter(List<Apple> apples) {
        List<Apple> result = new ArrayList<Apple>();
        for (Apple apple : apples) {
            if ("green".equals(apple.getColor())) {
                result.add(apple);
            }
        }
        return result;

    }
}
